void function(){
	var a = $('.wrapper').offset().top,$b = $('.addsMenu,.addImage'),arr = (function(){
		var o = [];
		i = $.each($('h1'),function(){
			o.push($(this).offset().top-$('.topbtnbox').height());
		});
		return o;
	})(),atind = function(a){
		if(a<arr[1])
			return 0;
		if(a>=arr[1]&&a<arr[2])
			return 1;
		if(a>=arr[2])
			return 2;
	},ind = atind($(window).scrollTop());
	b = function(){
		var s_top = $(window).scrollTop();
		s_top>a?$('.topbtnbox').css({'position':'fixed','left':'50%','margin-left':'-468px'}):$('.topbtnbox').css({'position':'absolute','left':'0','margin-left':''});
		s_top>130?$b.css({'position':'fixed','top':'30px'}):$b.css({'position':'absolute','top':'130px'});
		if(ind!=atind(s_top)){
			ind = atind(s_top);
			$('.addsMenu .li').removeClass('act').eq(ind).addClass('act');
		}
	},$valshoworhide = function(){
		return $.each($(this),function(){
			var val =  $(this).parent().find('.val'),self = $(this),showorhide = function(){
				val =  $(this).parent().find('.val'),self = $(this);
				if($.trim(self.val())!=''){
					val.hide();
				}else{
					val.show();
				}
			};
			if(val.length){
				val.click(function(){self.focus()});
				self.focus(function(){
					$(this).bind('input',showorhide).bind('propertychange',showorhide)
				}).blur(showorhide);
				showorhide.call(this);
			}
		});
	},$remainnumber = function(){
		return $.each($(this),function(){
			var val =  $(this).parent().find('.inttall'),self = $(this),caninleng = parseInt(val.find('span').text()),changenumber = function(){
				val =  $(this).parent().find('.inttall'),self = $(this),num = $(this).val().length;
				val.find('span').text(caninleng-num);
			};
			if(val.length){
				$(this).bind('input',changenumber).bind('propertychange',changenumber);
			}
			changenumber.call(this);
		});
	},checkoneClick = function(){
		$(this).each(function(){
			if($(this).parent().hasClass('word')){
				var a = $(this).next();
				a.html('<span>文字定制</span>');
				if($(this).prop('checked')){
					a.append('<div class="newinputtype"><input type="text" ><i>╲</i><div class="val">可订制文字数量上限</div></div>'+
	'<div class="inputright">'+
	'	个(汉字)'+
	'	<b>拖拽主图的标注点来标明作品可订制内容的位置。</b>'+
	'</div>');
				}else{
					a.append('<i>提示：当作品可以进行文字内容订制时设置此项。</i>');
				}
			}else if($(this).parent().hasClass('style')){
				var a = $(this).parent().parent().parent();
				if($(this).prop('checked')){
					a.after(_.template($('.styledemo').html(),{}));
				}else{
					if(!a.next().hasClass('styledemo'))
					a.next().remove();
				}
				$.resetmoveimg();
			}
		});
	},$liuichengmove = function(){
		var _this = $(this);
		$(this).each(function(i,o){

			var self = $(this),one = self.parent().parent(),h = one.height(),$space = $('<div class="SPACE"></div>'),position = [],index,textarr = ['一','二','三','四','五','六','七','八','九','十'],
			mousemove = function(event){
				var changeY = event.pageY-position[1]
				one.css({'top':position[0]+changeY+'px'});
				setindex(changeY);
				if(changeY<0)
					$('.process .one').eq(index).before($space);
				else{
					$('.process .one').eq(index).after($space);
				}
				return false;
			},mouseup = function(){
				$(document).unbind();
				one.attr('style','');
				$('.SPACE').after(one).remove();
				$(_this.unbind().selector).liuichengmove();
				$('.process .one').each(function(i){
					$(this).find('.ind').text('第'+textarr[i]+'步：');
				})
				$.resetmoveimg();
			},setindex = function(l){
				index = i - parseInt(-l/h);
				if(index<0)index = 0;
				else if(index>_this.length-1)index = _this.length-1;
			};
			self.mousedown(function(event){
				if(event.which==1){
					position.push(one.offset().top-$(window).scrollTop());
					position.push(event.pageY);
					one.css({'position':'fixed','z-index':'20','left':one.offset().left+'px','top':one.offset().top-$(window).scrollTop()+'px'}).before($space);
					$(document).mousemove(mousemove).mouseup(mouseup);
				}
			});
		});
		return this;
	},
	init = function(){
		$.fn.extend({valshoworhide:$valshoworhide,remainnumber:$remainnumber,liuichengmove:$liuichengmove})
		$('input[type="text"],textarea').valshoworhide().remainnumber();
		$('.addsMenu .li').click(function(){
			$(window).scrollTop(arr[$(this).index()]);
		}).removeClass('act').eq(ind).addClass('act');
		b();
		window.onscroll = b;
		checkoneClick.call($('.checkone input[type="checkbox"]').click(checkoneClick));
		$('.ibtn .mov').liuichengmove();
		// var _t;
		// window.onbeforeunload = function()
		// {
		//     setTimeout(function(){_t = setTimeout(onunloadcancel, 0)}, 0);
		//     return "真的离开?";
		// }
		
		
		// window.onunloadcancel = function()
		// {
		//     clearTimeout(_t);
		//     //alert("取消离开");
		// }
	};
	init();
}();
